package com.markyao.controller;

import com.markyao.dao.pojo.User;
import com.markyao.service.CartService;
import com.markyao.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    CartService cartService;

    @GetMapping("getCarts")
    public Result findCart(HttpSession session){
        User user = (User) session.getAttribute("user");

        return cartService.findByUid(user.getUid());
    }

    @GetMapping("num/add/{cid}")
    public Result addNum(@PathVariable("cid")Integer cid){
        return cartService.add(cid);
    }

    @GetMapping("num/reduce/{cid}")
    public Result reduceNum(@PathVariable("cid")Integer cid){
        return cartService.sub(cid);
    }

    @GetMapping("list")
    public Result cartList(Integer[] cids){
        return cartService.findByCids(cids);
    }
}
